<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Source extends Model
{
    use HasFactory;

    protected $table = 'sp_source';
    protected $primaryKey = 'id';
    public $timestamps = false;

    //status状态：1启用 0禁用
    const SOURCE_STATUS_ENABLE = 1;//启用
    const SOURCE_STATUS_DISABLE = 0;//禁用

    //获取来源信息
    protected function GetSource($where)
    {
        $category = $this
            ->where($where)
            ->get();
        $category = $category ? $category->toArray() : [];
        return $category;
    }

    //订单来源列表
    protected function GetSourceList($pageSize, $where)
    {
        $data = $this
            ->where($where)
            ->orderBy('id', 'desc')
            ->paginate($pageSize);
        $data = $data ? $data->toArray() : array();
        return $data;
    }

    //添加
    protected function addData($data)
    {
        return $data = $this->insert($data);
    }

    //根据id修改
    protected function editDataById($id, $data)
    {
        $where = array(
            'id' => $id,
        );
        return $data = $this->where($where)->update($data);
    }

}
